import { messages, handleHonest } from "share/common";
import React from 'react'
import { connect } from 'react-redux'
import { Form, Input, Select, Button, Row, Col, Checkbox, InputNumber, DatePicker, Radio, message } from 'antd'
const FormItem = Form.Item;
const TextArea = Input.TextArea;
const CheckboxGroup = Checkbox.Group;
const RadioGroup = Radio.Group;
const Option = Select.Option;

import beepTimerService from 'containers/setting/beep-timer/beep-timer.service'
import moment from 'moment'
import 'styles/setting/beep-timer/beep-form.scss'
import constants from "share/constants";

class BeepForm extends React.Component{
  constructor(props) {
    super(props);
    this.state = {
      info: {},
      paramsData: {},
      fromDataOptions:[],
      options : [],
      bankCardTypesOption:[],
      remindTypesOption:[
        {label: messages('setting.key65'/*APP消息*/), value: "APP"},
        {label: messages('setting.key66'/*邮件提醒*/), value: "EMAIL"},
      ],
      consumeTypesOption:[
        {label: messages('setting.key67'/*未生成费用的消费*/), value: "BANK_TRAN_NOT_CREATED_INVOICE"},
        {label: messages('setting.key68'/*已生成未关联报销单的费用*/), value: "BANK_TRAN_NOT_REFERENCED_REPORT"},
        {label: messages('setting.key69'/*已生成报销单未提交的费用*/), value: "BANK_TRAN_NOT_PASSED_REPORT"},
      ],
      billingPeriodTypesOption:[
        {label: messages('setting.key70'/*本月账单*/), value: "CURRENT_MONTH"},
        {label: messages('setting.key71'/*上月账单*/), value: "LAST_MONTH"},
      ],
      invoiceLabelsOption: [],
      invoiceStatusOption: [
        {label: messages('setting.key72'/*未关联报销单*/), value: 0},
        {label: messages('setting.key73'/*已关联报销单*/), value: 1}
      ],
      targetOption: [
        {label: messages('setting.key74'/*本人*/), value: 0},
        {label: messages('setting.key75'/*直属领导*/), value: 1},
        {label: messages('setting.key76'/*部门经理*/), value: 2}
      ],
      repaymentOption: [
        {label: messages('setting.key1302')/*申请人*/, value: 'CREATED_BY'},
        {label: messages('setting.key1870')/*收款人（仅限员工）*/, value: 'PAYEE'},
        {label: messages('setting.key960')/*财务*/, value: 'FINANCE'}
      ],
      expenseDisabled: true,
      tips: '',
      repaymentType: messages('setting.key1871')/*#发送基准日#*/,
      fitObj: '',
      invoiceOption: [],
      loanOption: [],
      expenseOptions: [],
      honestOption: []
    };
  }

  componentDidMount() {
    const { type } = this.props;
    this.setState({
      info: this.props.editData,
      paramsData: JSON.parse(this.props.editData.params || '{}')
    }, () => {
      const { paramsData } = this.state;
      paramsData && paramsData.invoiceStatus && ~paramsData.invoiceStatus.indexOf(1) && this.setState({expenseDisabled: false});
      let fitObj = '';
      let tips = '';
      paramsData && paramsData.formOids && (fitObj = 'formOids');
      paramsData && paramsData.loanTypeIds && (fitObj = 'loanTypeIds');
      if (type === "expense-report") {
        tips = messages('setting.key77'/*您有（费用发生日期）发生的费用，需尽快报销*/);
        paramsData && paramsData.target && (
          (paramsData.target === 1 || paramsData.target === 2) ?
            (tips = messages('setting.key1438', {arg1: paramsData.content}/*(费用所属人姓名/工号）有（费用发生日期)发生的费用，{arg1}*/)) :
            (tips = messages('setting.key1439', {arg1: paramsData.content}/*您有（费用发生日期）发生的费用，{arg1}*/))
        );
      }
      if (type === "expense-invoice") {
        tips = messages('setting.key1975')/*（若已交票，请忽略此提醒）您的【报销单号码】报销单，需尽快交票*/
      }
      this.setState({ tips, fitObj })
    });
    if (type === "traver") {
      this.getBillsOptions();
    }
    if (type === "business-card") {
      this.getBankCardOption();
    }
    if (type === "expense-report") {
      this.getLabelsOption();
    }
    if (type === "repayment") {
      this.getFitObjOption();
    }
    if (type === "expense-invoice") {
      this.getExpenseOptions();
    }
  };

  //获取差旅／借款申请单单据列表
  getBillsOptions(){
    const { company } = this.props;
    let method = this.props.type === 'traver' ? 'getAllTraverApprove' : 'getAllLoanApprove';
    beepTimerService[method](company.companyOID).then(res => {
      let fromDataOptions = [];
      res.data.map(item => {
        fromDataOptions.push({label: item.formName, value:item.formOID})
      });
      this.setState({ fromDataOptions })
    })
  }

  //获取商务卡列表
  getBankCardOption(){
    beepTimerService.getBusinessCardType().then(res => {
      let bankCardTypesOption = [];
      res.data.rows.map(item => {
        bankCardTypesOption.push({label: item.description, value: item.cardTypeCode})
      });
      this.setState({ bankCardTypesOption })
    })
  }

  getLabelsOption(){
    beepTimerService.getInvoiceLabels().then(res => {
      let invoiceLabelsOption = [];
      res.data.map(item => {
        invoiceLabelsOption.push({label: item.name, value: item.id})
      });
      this.setState({invoiceLabelsOption});
    })
    this.handleHonestRules('ExpenseReportNoticeTask');
  }

  handleHonestRules = (taskConfigCode) => {
    const { company } = this.props;
    beepTimerService.getHonestRule({ companyOID: company.companyOID, taskConfigCode })
      .then(res => {
        this.setState({
          honestOption: res.data
        })
      })
  };

  getFitObjOption = () => {
    const { company } = this.props;
    Promise.all([
      beepTimerService.getAllInvoiceType(company.companyOID),
      beepTimerService.getAllLoanType(company.setOfBooksId),
      beepTimerService.getHonestRule({ companyOID: company.companyOID, taskConfigCode: 'RepaymentNoticeTask' })
    ]).then(res => {
      let invoiceOption = [];
      let loanOption = [];
      res[0].data.map(item => {
        let temp = {
          label: item.formName,
          value: item.formOID
        };
        invoiceOption.push(temp);
      });
      res[1].data.map(item => {
        let temp = {
          label: item.description,
          value: item.id
        };
        loanOption.push(temp);
      });
      this.setState({
        invoiceOption,
        loanOption,
        honestOption: res[2].data
      })
    }).catch(() => {
      message.error(messages('setting.key1872')/*系统异常*/);
    });
  };

  //获取报销单选项
  getExpenseOptions = () => {
    const { company } = this.props;
    beepTimerService.getExpenseList(company.companyOID).then(res => {
      let expenseOptions = [];
      res.data && res.data.map(item => {
        expenseOptions.push({ label: item.formName, value: item.formOID, key: item.formOID })
      });
      this.setState({ expenseOptions })
    })
    this.handleHonestRules('ExpenseReportPasteReceiptNoticeTask');
  };

  //保存
  handSubmit = (e) => {
    e.preventDefault();
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        values.id = this.props.editData.id;
        this.props.submitHandle(values);
      }
    })
  };

  //取消
  handCancel =()=>{
    this.props.handCancel(this.props.editData);
  };

  getExpenseInit = () => {
    const { info, paramsData } = this.state;
    let result = [];
    if(info.id){
      paramsData.status.map((item,index) => {
        result.push(`${item}${item === '1001' ? paramsData.rejectType[index] : ''}`)
      });
    }
    return result;
  };

  invoiceStatusChange = (checkedValues) => {
    this.setState({expenseDisabled: ~checkedValues.indexOf(1) ? false : true});
  };

  setTips = (e) => {
    const { getFieldValue } = this.props.form;
    const { type } = this.props;
    if (type === 'expense-report') {
      let content = getFieldValue('content') || messages('setting.key78'/*需尽快报销*/);
      let result = (
        e.target.value === 0 ? messages('setting.key1439', {arg1: content}/*您有（费用发生日期）发生的费用，{arg1}*/) :
          messages('setting.key1440', {arg1: content}/*(费用所属人姓名/工号）有（费用发生日期 ）发生的费用，{arg1}*/)
      );
      this.setState({ tips: result });
    }
    if (type === 'expense-invoice') {
      let content = getFieldValue('content') || messages('setting.key1976')/*需尽快交票*/;
      let result = (
        e.target.value === 0 ? messages('setting.key1977',{arg1:content})/*（若已交票，请忽略此提醒）您的【报销单号码】报销单，{arg1}*/ : messages('setting.key1978',{arg1:content})/*(单据所属人姓名/工号）的【报销单号码】报销单，{arg1}*/
      );
      this.setState({ tips: result });
    }
  };

  changeTips = (e) => {
    const { getFieldsValue } = this.props.form;
    const { type } = this.props;
    let target = getFieldsValue().target;
    if (type === 'expense-report') {
      let content = e.target.value || messages('setting.key78'/*需尽快报销*/);
      let result = (
        target === 0 ? messages('setting.key1439', {arg1: content}/*您有（费用发生日期）发生的费用，{arg1}*/) :
          messages('setting.key1440', {arg1: content}/*(费用所属人姓名/工号）有（费用发生日期 ）发生的费用，{arg1}*/)
      );
      this.setState({ tips: result });
    }
    if (type === 'expense-invoice') {
      let content = e.target.value ? e.target.value : messages('setting.key1976')/*需尽快交票*/;
      let result = (
        target === 0 ? messages('setting.key1977',{arg1:content})/*（若已交票，请忽略此提醒）您的【报销单号码】报销单，{arg1}*/ : messages('setting.key1978',{arg1:content})/*(单据所属人姓名/工号）的【报销单号码】报销单，{arg1}*/
      );
      this.setState({ tips: result });
    }
  };

  getRepaymentType = value => {
    let res = messages('setting.key1871')/*#发送基准日#*/;
    switch (value){
      case 'BEFORE_PLANED_REPAYMENT_DATE':
        res = messages('setting.key1480')/*预计还款日期前*/;
        break;
      case 'AFTER_APPROVED_DATE':
        res = messages('setting.key1873')/*审批通过日期后*/;
        break;
      case 'AFTER_AUDIT_DATE':
        res = messages('setting.key1874')/*审核通过日期后*/;
        break;
    }
    this.setState({ repaymentType: res });
  };

  setFitObj = e => {
    let temp = [];
    temp[this.state.fitObj] = [];
    this.props.form.setFieldsValue(temp);
    this.setState({fitObj: e.target.value});
  };

  render(){
    const { type, titlePlaceholder, contentPlaceholder, loading } = this.props;
    const { getFieldDecorator } = this.props.form;
    const { info, paramsData, fromDataOptions, remindTypesOption, bankCardTypesOption, consumeTypesOption,
      billingPeriodTypesOption, invoiceStatusOption, targetOption, expenseDisabled, tips, invoiceLabelsOption,
      repaymentOption, repaymentType, fitObj, invoiceOption, loanOption, expenseOptions, honestOption
    } = this.state;
    const hourOption=[];
    const dateOption =[];
    for(let i = 0; i <= 23; i++) {
      hourOption.push(<Select.Option value={String(i)} key={String(i)}>{type === "business-card" ? i : i + ":00"}</Select.Option>)
    }
    for(let i = 1; i <= 31; i++) {
      dateOption.push(<Select.Option value={String(i)} key={String(i)}>{i}</Select.Option>)
    }
    const formItemLayout = {
      labelCol: { span:24 },
      wrapperCol: { span:24 }
    };
    let expenseInit = [];
    type === 'expense-report' && (expenseInit = this.getExpenseInit());
    return (
      <div className="beep-form">
        <Form onSubmit={this.handSubmit}>
          <div className="common-form-style">
            <FormItem {...formItemLayout} label={messages('setting.key79'/*提醒标题*/)}>
              {getFieldDecorator('title', {
                rules: [{
                  required:true,
                  message: messages('common.can.not.be.empty', {name:messages('setting.key79'/*提醒标题*/)})
                }, {
                  max: 50,
                  message: messages('common.max.characters.length', {max: 50})
                }],
                initialValue: paramsData.title
              })(
                <Input placeholder={titlePlaceholder} className="form-width-35" />
              )}
            </FormItem>
            <FormItem {...formItemLayout}
                      label={<span>{messages('setting.key80'/*提醒内容*/)}<br/>{tips}</span>}>
              {getFieldDecorator('content', {
                rules: [{
                  required:true,
                  message: messages('common.can.not.be.empty', {name:messages('setting.key80'/*提醒内容*/)})
                }, {
                  max: 100,
                  message: messages('common.max.characters.length', {max: 100})
                }],
                initialValue: paramsData.content
              })(
                <TextArea placeholder={contentPlaceholder} className="form-width-35" onChange={this.changeTips}/>
              )}
            </FormItem>
          </div>

          {type === "regularly" && (
            <Row>
              <Col span={5}>
                <FormItem {...formItemLayout} label={messages('setting.key81'/*发送日期*/)}>
                  {getFieldDecorator('sendDate', {
                    rules: [{
                      required: true,
                      message: messages('common.please.select')/*请选择*/
                    }],
                    initialValue: info.id && info.month && info.date ?
                      moment(new Date(`${new Date().getFullYear()}-${info.month}-${info.date}`)) : undefined
                  })(
                    <DatePicker format="MM-DD" style={{width: '100%'}}/>
                  )}
                </FormItem>
              </Col>
              <Col span={5} offset={1}>
                <FormItem {...formItemLayout} label={messages('setting.key82'/*发送时间*/)} >
                  {getFieldDecorator('hour', {
                    rules: [{
                      required:true,
                      message: messages('common.please.select')/*请选择*/
                    }],
                    initialValue: info.id ? info.hour + ':00' : undefined
                  })(
                    <Select placeholder={messages('common.please.select')/*请选择*/}>
                      {hourOption}
                    </Select>
                  )}
                </FormItem>
              </Col>
            </Row>
          )}

          {(type === "traver") && (
            <div className="traver-borrow-form">
              <Row>
                <Col span={12}>
                  <FormItem {...formItemLayout} label={messages('setting.key81'/*发送日期*/)} >
                    <span>{messages(type === 'traver' ? 'setting.key1479' : 'setting.key1480')}</span>
                    {getFieldDecorator('remindDay', {
                      rules: [{
                        required:true,
                        message: messages('common.can.not.be.empty', {name:messages('setting.key81'/*发送日期*/)})
                      }],
                      initialValue: info.id ? paramsData.remindDay : ''
                    })(
                      <InputNumber min={1} precision={0} placeholder={messages('common.enter')/*请输入*/}/>
                    )}
                    <span>{messages('setting.key83'/*天提醒员工*/)}{/*天提醒员工*/}</span>
                  </FormItem>
                </Col>
                <Col span={5} offset={1}>
                  <FormItem {...formItemLayout} label={messages('setting.key82'/*发送时间*/)} >
                    {getFieldDecorator('hour', {
                      rules: [{
                        required:true,
                        message: messages('common.can.not.be.empty', {name:messages('setting.key81'/*发送日期*/)})
                      }],
                      initialValue: info.id ? info.hour + ':00' : undefined
                    })(
                      <Select placeholder={messages('common.please.select')/*请选择*/}>
                        {hourOption}
                      </Select>
                    )}
                  </FormItem>
                </Col>
              </Row>
              <Row>
                <Col>
                  <FormItem {...formItemLayout} label={messages('setting.key84'/*适用单据*/)} >
                    {getFieldDecorator('formOIDs', {
                      rules: [{
                        required:true,
                        message: messages('common.can.not.be.empty', {name:messages('setting.key84'/*适用单据*/)})
                      }],
                      initialValue: info.id ? paramsData.formOIDs : []
                    })(
                      <CheckboxGroup>
                        {fromDataOptions.map(option => {
                          return <Checkbox key={option.value} value={option.value}>{option.label}</Checkbox>
                        })}
                      </CheckboxGroup>
                    )}
                  </FormItem>
                </Col>
              </Row>
            </div>
          )}

          {type === "business-card" && (
            <div className="business-card-form">
              <div className="ant-col-24 ant-form-item-label">
                <label className="ant-form-item-required">{messages('setting.key81'/*发送日期*/)}</label>
              </div>
              <Row>
                <Col span={2} className="col-text">{messages('setting.key85'/*每月*/)}{/*每月*/}</Col>
                <Col span={3}>
                  <FormItem {...formItemLayout} colon={false}>
                    {getFieldDecorator('date', {
                      rules: [{
                        required:true,
                        message: messages('common.select')/*请选择*/
                      }],
                      initialValue: info.id ? info.date : undefined
                    })(
                      <Select placeholder={messages('common.select')/*请选择*/}>
                        {dateOption}
                      </Select>
                    )}
                  </FormItem>
                </Col>
                <Col span={1} className="col-text">{messages('setting.key86'/*日*/)}{/*日*/}</Col>
                <Col span={3}>
                  <FormItem {...formItemLayout} colon={false}>
                    {getFieldDecorator('hour', {
                      rules: [{
                        required:true,
                        message: messages('common.select')//请选择
                      }],
                      initialValue: info.id ? info.hour : undefined
                    })(
                      <Select placeholder={messages('common.select')/*请选择*/}>
                        {hourOption}
                      </Select>
                    )}
                  </FormItem>
                </Col>
                <Col span={8} style={{textAlign: 'left'}} className="col-text">&nbsp;&nbsp;{messages('setting.key87'/*时提醒员工*/)}</Col>
              </Row>
              <FormItem {...formItemLayout} label={messages('setting.key88'/*提醒方式*/)} >
                {getFieldDecorator('remindTypes', {
                  rules: [{
                    required:true,
                    message: messages('common.can.not.be.empty', {name:messages('setting.key88'/*提醒方式*/)})
                  }],
                  initialValue: info.id ? paramsData.remindTypes : []
                })(
                  <CheckboxGroup options={remindTypesOption}/>
                )}
              </FormItem>
              <FormItem {...formItemLayout} label={messages('setting.key89'/*商务卡*/)} >
                {getFieldDecorator('bankCardTypes', {
                  rules: [{
                    required:true,
                    message: messages('common.can.not.be.empty', {name:messages('setting.key89'/*商务卡*/)})
                  }],
                  initialValue: info.id ? paramsData.bankCardTypes : []
                })(
                  <CheckboxGroup options={bankCardTypesOption}/>
                )}
              </FormItem>
              <FormItem {...formItemLayout} label={messages('setting.key90'/*消费数据类型*/)} >
                {getFieldDecorator('consumeTypes', {
                  rules: [{
                    required: true,
                    message: messages('common.can.not.be.empty', {name:messages('setting.key90'/*消费数据类型*/)})
                  }],
                  initialValue: info.id ? paramsData.consumeTypes : []
                })(
                  <CheckboxGroup options={consumeTypesOption}/>
                )}
              </FormItem>
              <FormItem {...formItemLayout} label={messages('setting.key91'/*账单期数*/)} >
                {getFieldDecorator('billingPeriodTypes', {
                  rules: [{
                    required: true,
                    message: messages('common.can.not.be.empty', {name:messages('setting.key91'/*账单期数*/)})
                  }],
                  initialValue: info.id ? paramsData.billingPeriodTypes : []
                })(
                  <CheckboxGroup options={billingPeriodTypesOption}/>
                )}
              </FormItem>
            </div>
          )}

          {(type === "expense-report" || type === "expense-invoice") && (
            <div className="expense-report-style">
              <div className="target-and-type">
                <Row>
                  <Col span={3} className="reminder-target">
                    <label className="ant-form-item-required">{messages('setting.key92'/*提醒对象:*/)}</label>
                  </Col>
                  <Col span={21}>
                    <FormItem {...formItemLayout} colon={false}>
                      {getFieldDecorator('target', {
                        rules: [{
                          required: true,
                          message: messages('common.can.not.be.empty', {name:messages('setting.key93'/*提醒对象*/)})
                        }],
                        initialValue: info.id ? paramsData.target : 0
                      })(
                        <RadioGroup options={targetOption} onChange={this.setTips}/>
                      )}
                    </FormItem>
                  </Col>
                </Row>
                <Row>
                  <Col span={3} style={{textAlign:"left"}}>
                    <label className="ant-form-item-required">{messages('setting.key94'/*提醒方式:*/)}</label>
                  </Col>
                  <Col span={21}>
                    <FormItem {...formItemLayout} colon={false}>
                      {getFieldDecorator('remindTypes', {
                        rules: [{
                          required: true,
                          message: messages('common.can.not.be.empty', {name:messages('setting.key95'/*提醒方式*/)})
                        }],
                        initialValue: info.id ? paramsData.remindTypes : []
                      })(
                        <CheckboxGroup options={remindTypesOption}/>
                      )}
                    </FormItem>
                  </Col>
                </Row>
                <Row>
                  <Col span={3} style={{textAlign:"left"}}><label>{messages('setting.key2216')/*信用规则：*/}</label></Col>
                  <Col span={9}>
                    <FormItem {...formItemLayout} colon={false}>
                      {getFieldDecorator('conditionId', {
                        initialValue: info.conditionId
                      })(
                        <Select
                          getPopupContainer={() => document.getElementsByClassName('expense-report-style')[0]}
                          placeholder={messages('common.select'/*请选择*/)}
                          optionLabelProp="title">
                          {
                            honestOption.map(item =>
                              <Option key={item.id} title={item.ruleCondition} style={{whiteSpace: 'unset'}}>
                                {item.ruleCondition} - {item.ruleConditionCode}
                                <br/>
                                {item.modelCode} - {item.modelName}
                                <br/>
                                {item.comment}（{handleHonest(item)}）{!item.valid && <span style={{ color: '#FF6680' }}>（{messages('common.status.disable')/*禁用*/}）</span>}
                              </Option>
                            )
                          }
                        </Select>
                      )}
                    </FormItem>
                  </Col>
                </Row>
              </div>
              <Row>
                <Col span={12}>
                  <div className="ant-col-24 ant-form-item-label">
                    <label className="ant-form-item-required">{messages('setting.key81'/*发送日期*/)}</label>
                  </div>
                  <Col span={type === 'expense-report' ? 6 : 9} className="col-text-left">
                    {type === 'expense-report' ?
                      messages('setting.key96'/*在费用发生日期*/) : messages('setting.key1979')/*在报销单首个打印节点后*/}
                  </Col>
                  <Col span={3} offset={1}>
                    <FormItem {...formItemLayout} colon={false} >
                      {getFieldDecorator('remindDay', {
                        rules: [{
                          required: true,
                          message: messages('common.please.select')/*请选择*/
                        }],
                        initialValue: info.id && paramsData.remindDay ? paramsData.remindDay : undefined
                      })(
                        <InputNumber step={1} min={1} precision={0} style={{width:'100%'}}/>
                      )}
                    </FormItem>
                  </Col>
                  <Col span={5} className="col-text-right" offset={1}>{messages('setting.key97'/*天后提醒员工*/)}</Col>
                </Col>
                <Col span={5} offset={1}>
                  <FormItem {...formItemLayout} label={messages('setting.key82'/*发送时间*/)} >
                    {getFieldDecorator('hour', {
                      rules: [{
                        required:true,
                        message: messages('common.please.select')/*请选择*/
                      }],
                      initialValue: info.id ? info.hour + ':00' : "10:00"
                    })(
                      <Select placeholder={messages('common.please.select')/*请选择*/}>
                        {hourOption}
                      </Select>
                    )}
                  </FormItem>
                </Col>
              </Row>
              {type === "expense-report" && (
                <div>
                  <div className="ant-col-24 ant-form-item-label"><label>{messages('setting.key98'/*需提醒报销的费用*/)}</label></div>
                  <Row>
                    <Col span={3} style={{textAlign:"left"}}><label className="ant-form-item-required">{messages('setting.key99'/*费用包含标签:*/)}</label></Col>
                    <Col span={21}>
                      <FormItem {...formItemLayout} colon={false}>
                        {getFieldDecorator('labels', {
                          rules: [{
                            required: true,
                            message: messages('common.can.not.be.empty', {name:messages('setting.key100'/*费用包含标签*/)})
                          }],
                          initialValue: info.id ? paramsData.labels : []
                        })(
                          <CheckboxGroup options={invoiceLabelsOption}/>
                        )}
                      </FormItem>
                    </Col>
                  </Row>
                  <Row>
                    <Col span={3} style={{textAlign:"left"}}><label className="ant-form-item-required">{messages('setting.key101'/*费用报销状态:*/)}</label></Col>
                    <Col span={21}>
                      <FormItem {...formItemLayout} colon={false}>
                        {getFieldDecorator('invoiceStatus', {
                          rules: [{
                            required: true,
                            message: messages('common.can.not.be.empty', {name:messages('setting.key102'/*费用报销状态*/)})
                          }],
                          initialValue: info.id ? paramsData.invoiceStatus : []
                        })(
                          <CheckboxGroup options={invoiceStatusOption} onChange={this.invoiceStatusChange}/>
                        )}
                      </FormItem>
                    </Col>
                  </Row>
                  {
                    !expenseDisabled ? (
                      <Row>
                        <Col span={3} style={{textAlign:"left"}}><label className="ant-form-item-required">{messages('setting.key103'/*报销单状态:*/)}</label></Col>
                        <Col span={21}>
                          <FormItem {...formItemLayout} colon={false}>
                            {getFieldDecorator('expenseStatus', {
                              rules: [{
                                required: true,
                                message: messages('common.can.not.be.empty', {name:messages('setting.key104'/*报销单状态*/)})
                              }],
                              initialValue: expenseInit
                            })(
                              <CheckboxGroup options={[...constants.expenseStatus]} disabled={expenseDisabled}/>
                            )}
                          </FormItem>
                        </Col>
                      </Row>
                    ) : ''
                  }
                </div>
              )}
              {type === "expense-invoice" && (
                <div>
                  <div className="ant-col-24 ant-form-item-label">
                    <label className="ant-form-item-required">{messages('setting.key84'/*适用单据*/)}</label>
                  </div>
                  <FormItem {...formItemLayout} colon={false}>
                    {getFieldDecorator('formOids', {
                      rules: [{
                        required: true,
                        message: messages('common.can.not.be.empty', {name: messages('setting.key84'/*适用单据*/)})
                      }],
                      initialValue: info.id ? paramsData.formOids : []
                    })(
                      <CheckboxGroup options={expenseOptions}/>
                    )}
                  </FormItem>
                </div>
              )}
            </div>
          )}

          {
            type === "repayment" && (
              <div className="expense-report-style">
                <div style={{borderBottom:'1px solid #e8e8e8',marginBottom: '20px'}}>
                  <Row>
                    <Col span={3} style={{textAlign:"left"}}><label className="ant-form-item-required">{messages('setting.key92'/*提醒对象:*/)}</label></Col>
                    <Col span={21}>
                      <FormItem {...formItemLayout} colon={false}>
                        {getFieldDecorator('repaymentRemindPersonTypes', {
                          rules: [{
                            required: true,
                            message: messages('common.can.not.be.empty', {name:messages('setting.key93'/*提醒对象*/)})
                          }],
                          initialValue: info.id ? paramsData.repaymentRemindPersonTypes : []
                        })(
                          <CheckboxGroup options={repaymentOption}/>
                        )}
                      </FormItem>
                    </Col>
                  </Row>
                  <Row>
                    <Col span={3} style={{textAlign:"left"}}><label className="ant-form-item-required">{messages('setting.key94'/*提醒方式:*/)}</label></Col>
                    <Col span={21}>
                      <FormItem {...formItemLayout} colon={false}>
                        {getFieldDecorator('repaymentRemindTypes', {
                          rules: [{
                            required: true,
                            message: messages('common.can.not.be.empty', {name:messages('setting.key95'/*提醒方式*/)})
                          }],
                          initialValue: info.id ? paramsData.repaymentRemindTypes : []
                        })(
                          <CheckboxGroup options={remindTypesOption}/>
                        )}
                      </FormItem>
                    </Col>
                  </Row>
                  <Row>
                    <Col span={3} style={{textAlign:"left"}}><label>{messages('setting.key2216')/*信用规则：*/}</label></Col>
                    <Col span={9}>
                      <FormItem {...formItemLayout} colon={false}>
                        {getFieldDecorator('conditionId', {
                          initialValue: info.conditionId
                        })(
                          <Select placeholder={messages('common.select'/*请选择*/)} optionLabelProp="title">
                            {
                              honestOption.map(item =>
                                <Option key={item.id} title={item.ruleCondition} style={{whiteSpace: 'unset'}}>
                                  {item.ruleCondition} - {item.ruleConditionCode}
                                  <br/>
                                  {item.modelCode} - {item.modelName}
                                  <br/>
                                  {item.comment}（{handleHonest(item)}）{!item.valid && <span style={{ color: '#FF6680' }}>（{messages('common.status.disable')/*禁用*/}）</span>}
                                </Option>
                              )
                            }
                          </Select>
                        )}
                      </FormItem>
                    </Col>
                  </Row>
                </div>
                <Row>
                  <div className="ant-col-24 ant-form-item-label"><label className="ant-form-item-required">{messages('setting.key1875')/*发送基准日*/}</label></div>
                  <Col span={6}>
                    <FormItem {...formItemLayout} colon={false} >
                      {getFieldDecorator('repaymentRemindBaseDateType', {
                        rules: [{
                          required: true,
                          message: messages('common.please.select')/*请选择*/
                        }],
                        initialValue: info.id ? paramsData.repaymentRemindBaseDateType : undefined
                      })(
                        <Select onChange={this.getRepaymentType} placeholder={messages('common.please.select')/*请选择*/}>
                          <Option key={'BEFORE_PLANED_REPAYMENT_DATE'}>{messages('setting.key1480')/*预计还款日期前*/}</Option>
                          <Option key={'AFTER_APPROVED_DATE'}>{messages('setting.key1873')/*审批通过日期后*/}</Option>
                          <Option key={'AFTER_AUDIT_DATE'}>{messages('setting.key1874')/*审核通过日期后*/}</Option>
                        </Select>
                      )}
                    </FormItem>
                  </Col>
                </Row>
                <Row>
                  <Col span={12}>
                    <div className="ant-col-24 ant-form-item-label"><label className="ant-form-item-required">{messages('setting.key81'/*发送日期*/)}</label></div>
                    <Col span={6} className="col-text">{repaymentType}</Col>
                    <Col span={3} offset={1}>
                      <FormItem {...formItemLayout} colon={false} >
                        {getFieldDecorator('differenceDate', {
                          rules: [{
                            required: true,
                            message: messages('common.please.select')/*请选择*/
                          }],
                          initialValue: info.id && paramsData.differenceDate ? paramsData.differenceDate : undefined
                        })(
                          <InputNumber step={1} min={1} precision={0} style={{width:'100%'}}/>
                        )}
                      </FormItem>
                    </Col>
                    <Col span={5} className="col-text" offset={1}>{messages('setting.key83')/*天提醒员工*/}</Col>
                  </Col>
                  <Col span={5} offset={1}>
                    <FormItem {...formItemLayout} label={messages('setting.key82'/*发送时间*/)} >
                      {getFieldDecorator('hour', {
                        rules: [{
                          required:true,
                          message: messages('common.please.select')/*请选择*/
                        }],
                        initialValue: info.id ? info.hour + ':00' : undefined
                      })(
                        <Select placeholder={messages('common.please.select')/*请选择*/}>
                          {hourOption}
                        </Select>
                      )}
                    </FormItem>
                  </Col>
                </Row>
                <Row>
                  <Col span={3} style={{textAlign:"left",lineHeight: '32px'}}><label className="ant-form-item-required">{messages('setting.key1876')/*适用对象*/}</label></Col>
                  <Col span={21}>
                    <FormItem {...formItemLayout} colon={false}>
                      {getFieldDecorator('fitObj', {
                        rules: [{
                          required: true,
                          message: messages('common.can.not.be.empty', {name:''})
                        }],
                        initialValue: info.id ? (paramsData.formOids ? 'formOids' : 'loanTypeIds')  : undefined
                      })(
                        <RadioGroup options={[{
                          label: messages('setting.key485')/*单据类型*/,
                          value: 'formOids'
                        },{
                          label: messages('setting.key1554')/*借款类型*/,
                          value: 'loanTypeIds'
                        }]} onChange={this.setFitObj}/>
                      )}
                    </FormItem>
                  </Col>
                </Row>
                {
                  fitObj && (
                    <Row>
                      <FormItem {...formItemLayout} colon={false} >
                        {getFieldDecorator(fitObj, {
                          rules: [{
                            required: true,
                            message: messages('common.please.select')/*请选择*/
                          }],
                          initialValue: info.id ? paramsData[fitObj] : []
                        })(
                          <CheckboxGroup options={fitObj === 'formOids' ? invoiceOption : loanOption}/>
                        )}
                      </FormItem>
                    </Row>
                  )
                }
              </div>
            )
          }

          <Row>
            <FormItem wrapperCol={{ offset: 0 }}>
              <Button type="primary" htmlType="submit" loading={loading} style={{marginRight:'10px'}}>
                {messages('common.save')/*保存*/}
              </Button>
              <Button onClick={this.handCancel}>{messages('common.cancel')/*取消*/}</Button>
            </FormItem>
          </Row>
        </Form>
      </div>
    )
  }
}



function mapStateToProps(state) {
  return {
    company: state.login.company,
  }
}


BeepForm.propTypes = {
  type: React.PropTypes.string.isRequired, //选择类型 traver, business-card, regularly, expense-report, repayment, expense-invoice
  editData: React.PropTypes.object,
  loading: React.PropTypes.bool,        //保存按钮loading
  titlePlaceholder: React.PropTypes.string,   //提醒标题placeholder
  contentPlaceholder: React.PropTypes.string, //提醒内容placeholder
  submitHandle: React.PropTypes.func,  //保存
  handCancel: React.PropTypes.func,   //取消
};

BeepForm.defaultProps = {
  editData: {},
  loading: false,
  titlePlaceholder: messages('common.please.enter')/*请输入*/,
  contentPlaceholder: messages('common.please.enter')/*请输入*/,
  submitHandle: ()=>{},
  handCancel: ()=>{},
};

const WrappedBeepForm= Form.create()(BeepForm);

export default connect(mapStateToProps)(WrappedBeepForm);


